from __future__ import absolute_import, division

from gui.panda.base import *

from ..utils import ValueField


class WaterPlane(Object):
    parent    = Attribute()
    id        = Attribute()
    size      = Attribute()
    resources = Attribute()
    wind      = Attribute()
    
    root      = Attribute()
    
    def setup(self):
        maker = CardMaker('plane-' + self.id)
        maker.setFrame(0, self.size, 0, self.size)
        
        self.root = self.parent.attachNewNode(maker.generate())
        self.root.setPos(0, 0, 0.95)
        self.root.setP(-90)
        self.root.setTransparency(TransparencyAttrib.MDual)
        self.root.setShader(self.resources.load_shader('Water'))
        self.root.setShaderInput('wind',   Vec4(-0.01 * self.wind, 0.01 * self.wind, 0, 0))
        self.root.setShaderInput('detail', 12.0)
        self.root.setTexture(TextureStage('distortion'), self.resources.load_texture('Water Bumpmap'))
